package com.fh.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fh.admin.entity.UmsAdmin;
import com.fh.admin.service.IUmsAdminService;
import com.fh.po.UserSearch;
import com.fh.result.ResultObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台用户表 前端控制器
 * </p>
 *
 * @author F
 * @since 2021-05-11
 */
@RestController
@RequestMapping("/ums/admin")
public class UmsAdminController {

    @Autowired
    private IUmsAdminService umsAdminService;


    @GetMapping
    /*@PreAuthorize("hasAuthority('asdasd')")*/
    public ResultObject queryUserPage(Page<UmsAdmin> page, UserSearch  userSearch){
        QueryWrapper<UmsAdmin>queryWrapper=new QueryWrapper<>();

        if(StringUtils.isNotBlank(userSearch.getNickName())){
            queryWrapper.like("nick_name", userSearch.getNickName());
        }


        queryWrapper.orderByDesc("create_time");
        umsAdminService.page(page,queryWrapper);
        return  ResultObject.success(page);
    }
    @PostMapping
    public ResultObject  saveQrUpdateUser(@RequestBody UmsAdmin umsAdmin){
        umsAdminService.saveQrUpdateUser(umsAdmin);
        return ResultObject.success();
    }
    @GetMapping("/{userId}")
    public ResultObject getUserById(@PathVariable("userId")Long userId){
        UmsAdmin user=umsAdminService.getById(userId);
        return ResultObject.success(user);
    }


    //删除数据
    @DeleteMapping("/{iqd}")
    public String deleteBrand(@PathVariable("iqd") Long iqd){

        umsAdminService.removeById(iqd);
        return "success";
    }
    //批量删除
    @DeleteMapping
    public ResultObject batchDelUser(@RequestBody List<Long> ids){
        umsAdminService.removeByIds(ids);
        return ResultObject.success();

    }




}
